Socket
Socket
Sign inDemoInstall

p-from-callback

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    p-from-callback

Map a callback to a promise


Version published
Weekly downloads
6.9K
decreased by-16.2%
Maintainers
1
Install size
4.69 kB
Created
Weekly downloads
 

Readme

Source

p-from-callback

Build Status npm package Coverage Status

Map node-style callback to a promise

Install

$ npm install p-from-callback

Features

  • pure esm module
  • typescript types
  • supports multiple return values
  • 100% test coverage

Usage

import { readFile } from 'node:fs';
import fromCallback from 'p-from-callback';

fromCallback(cb => readFile("foo.txt", cb)).then(buf => buf.toString('utf8'));
fromCallback(cb => cb(undefined, "foo", "bar"), true)
    .then([foo, bar] => foo === "foo" && bar === "bar");

API

fromCallback<R>((cb: (err: any, res: R)): any): Promise<R>
fromCallback<R>((cb: (err: any, ...res: R[])): any, true): Promise<R[]>

Takes a callback resolver and returns a promise to the resolved value, or array of values when multi = true.

License

See the LICENSE file for license rights and limitations (MIT).

Keywords

FAQs

Last updated on 01 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc